﻿// -----------------------------------------------------------------------
// <copyright file="ViewModelLocator.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace mmonkey.ViewModels
{
    using mmonkey.core;
    using mmonkey.Modules;
    using GalaSoft.MvvmLight;
    
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// </summary>
    public class ViewModelLocator
    {
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            // prevent second initialization in design mode
            if (!SimpleContainer.Initialized)
            {
                SimpleContainer.Initialize(ViewModelBase.IsInDesignModeStatic);
                this.ConfigureContainer(ViewModelBase.IsInDesignModeStatic);
            }
        }

        public void ConfigureContainer(bool designMode)
        {
            SimpleContainer.Load(new AppNinjectModule());
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        public static MainViewModel MainStatic
        {
            get
            {
                var main = SimpleContainer.Resolve<MainViewModel>();
                return main;
            }
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        public MainViewModel Main
        {
            get
            {
                return MainStatic;
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            var list = SimpleContainer.ResolveAll<ICleanup>();
            foreach (var item in list)
            {
                item.Cleanup();
            }
        }
    }
}